﻿<template>
    <div class="ad-content">
        <div class="ad-main">
            <div class="ad-console-top">
                <div class="ad-console-top-name">清单字段</div>
                <div class="ad-console-top-body">
                </div>
                <div class="ad-console-top-end">
                </div>
            </div>
            <div class="ad-console-body">
  
                <div class="ad-console-toolbar" v-if="IsAdmin">
                   <el-button type="primary" size="small" icon="icon-plus4 el-icon--left"  @click="openDialog()">添加</el-button>
                </div>
                <div class="ad-card">
                    <el-table :data="list" size="mini" border style="width: 100%" @sort-change="handleSortChange">
                        <el-table-column type="index" width="55" label="序号" align="center"></el-table-column>
                        <el-table-column prop="FieldName" label="字段名称" align="left"></el-table-column>
                        <el-table-column prop="Tactic" label="排序" width="90" align="center">
                            <template slot-scope="scope">
                                <el-input-number :id="scope.row.FieldID" v-model="scope.row.Tactic" size="small" :controls="false" @blur="blur(scope.row)"style="width:66px;"></el-input-number>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" width="150" align="center" v-if="IsAdmin">
                            <template slot-scope="scope">
                                <el-button type="text" size="mini" @click="openDialog(scope.row.FieldID)">编辑</el-button>
                                <el-button type="text" size="mini" @click="openDialog(scope.row.FieldID)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <br />
                    <div style="text-align:center"><el-pagination v-if="count>0" background layout="prev, pager, next" :current-page="currentpage" :total="count" @current-change="pagerclick"></el-pagination></div>
                </div>
            </div>
            <el-dialog :title="title" class="dlg" v-dialogDrag :visible="showDialog" width="500px" @close="closeDialog()">
                <el-form :model="form" class="rule" status-icon :rules="rules" ref="form" label-width="80px">
                    <el-form-item label-width="0px">
                        <el-col :span="24">
                            <el-form-item label="temp" prop="FieldName">
                                <span slot="label">字段名</span>
                                <el-input v-model="form.FieldName" size="medium" placeholder="请选择字段名" ></el-input>
                              
                            </el-form-item>
                        </el-col>
                    </el-form-item>
                    <el-form-item style="margin-bottom:0px;">
                        <el-button type="primary" size="medium" @click="submit">提交</el-button>
                        <el-button size="medium" @click="closeDialog()">关闭</el-button>
                    </el-form-item>
                </el-form>
            </el-dialog>
        </div>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                list: [],
                showDialog: false,
                IsAdmin: false,
                ShowIndate: false,
                currentpage: 0,
                count:0,
                searchkey: '',
                title:'',
                TaskIDs: [],
                form: {
                    FieldID: 0,
                    FieldName: ''
                },
                rules: {
                    FieldName: [
                        { required: true, message: '请输入类别名称', trigger: 'blur' }
                    ]
                }
          

             
            }
        },
        mounted() {
            App.Page.init(this);
            this.load();
        },
        methods: {
            load() {
                App.Service.post("/plus/Yqd/QuotaField/GetList", { start: App.Fn.toStart(this.currentpage), limit: App.pagesize, searchkey: this.searchkey }).then((res) => {
                    if (res.success) {
                        this.IsAdmin = true;
                        this.count = res.totalcount;
                        this.list = res.data;
                    
                    }
                });
            },
            pagerclick(currentpage) {
                this.currentpage = currentpage;
                this.load();
            },
            search() {
                this.currentpage = 0;
                this.load();
            },
            refresh() {
                this.currentpage = 0;
                this.searchkey = 0;
                this.load();
            },
  
            closeDialog() {
                this.showDialog = false
                this.form  = {
                    FieldID: 0,
                    FieldName: ''
                }
            },

            submit() {
                this.$refs['form'].validate((valid) => {
                    if (valid) {
                        App.Service.post("/plus/Yqd/QuotaField/" + (this.form.FieldID > 0 ? "Edit" : "Add"), this.form).then((res) => {
                            if (res.success) {
                                this.closeDialog();
                                this.load();
                            }
                        });
                        return;
                    }
                });
            },
            openDialog(TaskID) {
                this.title = '添加字段';

                if (!TaskID) {
                    this.showDialog = true;
                    return;
                }
                this.title = '编辑字段';
                App.Service.post("/plus/Yqd/QuotaField/GetTaskN_O", { TaskID: TaskID }).then((res) => {
                    if (res.success) {
                        this.TaskInfo.TaskID = TaskID
                        this.TaskInfo.TaskName = TaskName
                        this.TaskInfo.data_O = res.data_O
                        this.TaskInfo.data_N = res.data_N
                        this.showDialog = true
                        //this.IsAdmin = true;
                        //this.count = res.totalcount;
                        //this.list = res.data;

                    }
                });
            },
            blur(row) {
                App.Service.post("/plus/Yqd/QuotaField/UpdateTop", { FieldID: row.FieldID, Tactic: row.Tactic }).then((res) => {
                    if (res.success) {
                        this.load();
                    }
                });
            }

        

        }
    };
</script>
